<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * FormativeLab
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		FormativeLab
 * @author		FormativeLab Dev Team
 * @copyright	Copyright (c) 2011 - 2013, FormativeLab, Inc.
 * @license		http://www.formativesoft.com/license/
 * @link		http://www.formativesoft.com/
 * @since		Version 2.0
 * @filesource ./application/controllers/Shahed.php
 */

// ------------------------------------------------------------------------

/**
 * FormativeLab Shahed Controller
 *
 * @package		FormativeLab
 * @subpackage	controllers
 * @category	controllers
 * @author		Formative Soft Ltd
 * @link		http://www.formativesoft.com/
 */

// ------------------------------------------------------------------------

class Shahed extends FSL_Controller {

	static $helpesr	= array();
	static $models	= array('M01I001001', 'M01I002001', 'M01I003001', 'M01I004001', 'M01I005001', 'M01I006001'
					  , 'M01I007001', 'M01I008001', 'M01I009001', 'M01I010001', 'M01I011001', 'M01I012001');

	public function __construct(){
        parent::__construct('defaults');
		$this->load->helper(self::$helpers);
		loadModel(self::$models);
    }
	
	
	public function index(){
		$this->output->set_status_header(200);
		$this->output->set_header('Content-type: text/html; charset=utf-8');
		print_r($this->M01I009001->findAll());
		echo 'index';
	}
	
	public function save(){
		$this->M01I009001->beginTrasaction();
		//$this->M01I009001->startTrasaction();
		
		$nameBn	= $this->M01I009001->findById(4)->nameBn;
		$model = new M01I009001();
		$model->id		= 10;
		$model->nameEn  = 'Ibrahim Sardar';
        $model->nameBn  =  $nameBn;
		$model->save(true);
		//$this->M01I009001->commitTrasaction();
		$this->M01I009001->rollbackTrasaction();
	}
	
	public function update(){
		$this->M01I009001->beginTrasaction();
		//$this->M01I009001->startTrasaction();		
		$model	= $this->M01I009001->findById(3);
		$model->nameEn  = 'Abdul Rahman';
		$model->update(true);
		$this->M01I009001->commitTrasaction();
		//$this->M01I009001->rollbackTrasaction();
	}
	
	public function lang(){
		//$this->lang->load('shahed', 'english');
		$this->lang->load('shahed', 'bangla');
		echo $this->lang->line('name');
	}
	
	public function json($offset=0, $limit=10){
		if(isGetRequest()){
			//$data   = $this->M01I00900->all($limit, $offset);
			//$data 	= $this->M01I00900->getResponseData($data, 10, true, 'successed!');
			//$this->render->jsonData($data);
			$this->M01I009001->jall();
		}
	}
	
	public function xml(){		
		$data 	= $this->M01I009001->all();
		$data 	= $this->M01I009001->getResponseData($data, 10);
		$this->render->simpleXML($data);
	}
		
	public function dom(){		
		$data 	= $this->M01I009001->all();
		$data 	= $this->M01I009001->getResponseData($data, 10);
		$this->render->standardXML($data);
	}
	
	public function logger(){
		log_message('error', 'Hello world hello the listener');
		echo 'logger';
	}
	
	public function rss(){				
		$items		= array();
		$data   	= $this->M01I009001->all();
		foreach($data as $index => $model){
			$item	= new RSSItem(
				'shahed/rss/' . $model->id,
				'shahed/rss/' . $model->id,
				$model->nameEn,
				new DateTime()
			);
			$items[] = $item;
		}	
		$channel	= new RSSChannel(
			'Shahed Feeds',
			'http://www.sahed.biz/feed',
			'sahed.biz all tutorial and feed goes here',
			'eng.shahed@gmail.com',
			$items
		);
		$rssFeed	= new RSSFeed($channel);
		$rssFeed->renderFeed();
	}
	
	public function transac(){
		$this->output->set_status_header(200);
		$this->output->set_header('Content-type: text/html; charset=utf-8');
		
		$this->db->trans_begin();
		//$this->db->trans_start();
		try{
			$x = 1;
			$y = 0;
			if($y == 0){
				throw new Exception('Division by zero.');
			}
			$z = $x/$y;
		}catch(Exception $e){
			//$this->db->trans_complete();
			//$this->db->trans_rollback();
			//$this->db->trans_off();
			log_message('error',  $e->getMessage());
		}
		echo $this->db->trans_status();
	}
	
	public function test(){
		$this->M01I009001->jall(4);
	}
	
	public function unicode(){
		$msg	= "shahed hossain\u09AE\u09B9\u09BE\u09A6\u09C7\u09B6\u09C7\u09B0 \u09A8\u09BE\u09AE \u09AC\u09BE\u0982\u09B2\u09BE\u09DF \u09B2\u09BF\u0996\u09C1\u09A8, \u0989\u09A6\u0983 \u098F\u09B6\u09BF\u09DF\u09BE, \u0987\u0989\u09B0\u09CB\u09AA";
		//$msg	= "\x09AE\x09B9\x09BE\x09A6\x09C7\x09B6\x09C7\x09B0 \x09A8\x09BE\x09AE \x09AC\x09BE\x0982\x09B2\x09BE\x09DF \x09B2\x09BF\x0996\x09C1\x09A8, \x0989\x09A6\x0983 \x098F\x09B6\x09BF\x09DF\x09BE, \x0987\x0989\x09B0\x09CB\x09AA";
		//$msg	= utf8_encode($msg);
		function hexToStr($hex){
			$string='';
			for ($i=0; $i < strlen($hex)-1; $i+=2)
			{
				$string .= chr(hexdec($hex[$i].$hex[$i+1]));
			}
			return $string;
		}
		$this->output->set_status_header(200);
		$this->output->set_header('Content-type: text/html; charset=utf-8');
		//echo utf8_encode(hexToStr($msg));
		echo json_decode("\"{$msg}\"");
	}
	
}

/* End of file Shahed.php */
/* Location: ./application/controllers/Shahed.php */